<?php

declare(strict_types=1);

namespace App\Amqp\Consumer;

use App\Utils\Notice\Notice;
use Hyperf\Amqp\Result;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use PhpAmqpLib\Message\AMQPMessage;

/**
 * @Consumer(exchange="notice", routingKey="notice", queue="notice", name ="NoticeConsumer", nums=1)
 */
class NoticeConsumer extends ConsumerMessage
{
    public function consumeMessage($data, AMQPMessage $message): string
    {
        $noticeName = $data['class_name'];
        /** @var Notice $notice */
        $notice = new $noticeName($data['data']);
        $notice->receiverId = $data['receive_id'];
        $notice->process();
        return Result::ACK;
    }
}
